/**
 * 
 */
package com.tomato.joke.task;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.AsyncTask;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.tomato.joke.R;

/**
 * 
 * @author defier
 */
public class RefreshMainTask extends AsyncTask<String, Integer, List<String>> {
	
	private ImageView imageView;
	private ListView listview;
	
    public RefreshMainTask(ImageView imageView, ListView listview) {
    	this.imageView = imageView;
    	this.listview = listview;
    }
    
    protected List<String> doInBackground(String... params) {
		return null;
    }

    @Override
    protected void onCancelled() {
        super.onCancelled();
    }
    
    @Override
    protected void onPostExecute(List<String> result) {
    	Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(imageView.getContext(), R.anim.animation);
		imageView.startAnimation(hyperspaceJumpAnimation);
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		SimpleAdapter adapter = new SimpleAdapter(imageView.getContext(), getData(),
												R.layout.main_list_item, new String[] { "thumbnail", "content", "uri" },
												new int[] { R.id.list_item_icon, R.id.list_item_content, R.id.list_item_id });
		listview.setAdapter(adapter);
//		imageView.clearAnimation();
	}
    @Override
    protected void onPreExecute() {
    	
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
    	
    }
    
    private List<Map<String, Object>> getData() {
		Integer[] images = { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher };
		String[] descs = { "���ķ��Ѱ�","���ķ��Ѱ�","���ķ��Ѱ�","���ķ��Ѱ�","���ķ��Ѱ�",
				"���ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ���","���ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ���","���ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ��ѿ��ķ���" };
		String[] urls = { "http://m.walkingp.com/handbook/jquery/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/",
				"http://m.walkingp.com/handbook/css/"};
		List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
		for (int i = 0; i < descs.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("thumbnail", images[i]);
			map.put("content", descs[i]);
			map.put("uri", urls[i]);
			items.add(map);
		}
		return items;
	}
 }
